home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
workbench
/
libs
/
newlooklib.lha
/
newlook
/
createpalettebutton.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-07
|
2KB
|
107 lines
/*
* CREATEPALETTEBUTTON.C
*/
#include "newlook.h"
static struct Border *CreatePaletteBorder(w,h,pen)
WORD w,h;
UBYTE pen;
{
struct Border *b;
SHORT *xy;
int numpairs= 2 * ( (w<h) ? w:h );
if(b= (struct Border *)SmartAllocate(BORDERSIZE))
{
if(xy= (SHORT *)SmartAllocate(2*numpairs*sizeof(SHORT)))
{
int n;
b->LeftEdge = 4;
b->TopEdge = 2;
b->FrontPen = pen;
b->BackPen = 0;
b->DrawMode = JAM1;
b->Count = numpairs;
b->XY = xy;
b->NextBorder = (struct Border *)NULL;
if(w<h)
{
short x;
for(x=n=0; n<2*numpairs; n+=2)
{
xy[n]= x;
xy[n+1]= (n%4) ? (h-1):0;
if(n%4) x++;
}
}
else /* h<w */
{
short y;
for(y=n=0; n<2*numpairs; n+=2)
{
xy[n+1]= y;
xy[n]= (n%4) ? (w-1):0;
if(n%4) y++;
}
}
}
else b= (struct Border *)SmartFree(b);
}
return b;
}
struct Gadget *CreatePaletteButton(x,y,w,h,pen,id)
WORD x,y,w,h;
UBYTE pen;
USHORT id;
{
struct Gadget *g;
struct Border *b0, *b1, *p;
ULONG UserHandle= SetNewLookHandle(PRIVATE_HANDLE);
if(g= (struct Gadget *)SmartAllocate(GADGETSIZE))
{
if(b0= CreateBorder(0,0,w,h,FALSE))
{
if(b1= CreateBorder(0,0,w,h,TRUE))
{
if(p= (struct Border *)CreatePaletteBorder(w-8,h-4,pen))
{
LastBorder(b0)->NextBorder= p;
/* LastBorder(b1)->NextBorder is NULL */
g->NextGadget = (struct Gadget *)NULL;
g->LeftEdge = x;
g->TopEdge = y;
g->Width = w;
g->Height = h;
g->Flags = GADGHIMAGE;
g->Activation = GADGIMMEDIATE|RELVERIFY;
g->GadgetType = BOOLGADGET;
g->GadgetRender = (APTR)b0;
g->SelectRender = (APTR)b1;
g->GadgetText = (APTR)NULL;
g->MutualExclude = (LONG)0L;
g->SpecialInfo = (APTR)NULL;
g->GadgetID = id;
g->UserData = (APTR)p; /* NewLook private !!! */
MakePrivateHandlePublic(UserHandle);
return g;
}
}
}
}
if(UserHandle != PRIVATE_HANDLE)
{ SmartFreeAll(PRIVATE_HANDLE);
(void)SetNewLookHandle(UserHandle);
}
return (struct Gadget *)NULL;
}